package com.ciei.dpagm.controller;

import com.alibaba.fastjson.JSONObject;
import com.ciei.dpagm.common.controller.BaseController;
import com.ciei.dpagm.entity.Users;
import com.ciei.dpagm.service.DriverLibraryService;
import com.ciei.dpagm.util.PageParam;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangyan
 * @date 2023/05/08
 */
@RestController
@RequestMapping("driverLibrary")
public class DriverLibraryController extends BaseController {

    @Autowired
    private DriverLibraryService driverLibraryService;

    @RequestMapping("loadGrid")
    public JSONObject loadGrid(@RequestBody JSONObject page) {
        PageParam pageParam=getPageParams(page);
        return driverLibraryService.loadGrid(pageParam);
    }

    @RequestMapping("getOneSlaveDriverInfo")
    public JSONObject getOneSlaveDriverInfo(@RequestBody JSONObject data) {
        return driverLibraryService.getOneSlaveDriverInfo(data);
    }

    @RequestMapping("loadTreeByCategory")
    public JSONObject loadTreeByCategory(@RequestBody JSONObject data) {
        return driverLibraryService.loadTreeByCategory(data);
    }

    @RequestMapping("loadDriverLibraryConfig")
    public JSONObject loadDriverLibraryConfig(@RequestBody JSONObject data) {
        return driverLibraryService.loadTreeByCategory(data);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:add")
    @RequestMapping("add")
    public JSONObject add(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return driverLibraryService.add(data,currentUser);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:editDriverDefinitionFile")
    @RequestMapping("updateByFile")
    public JSONObject updateByFile(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return driverLibraryService.updateByFile(data,currentUser);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:uploadDriverTemplateFile")
    @RequestMapping("addDriverFile")
    public JSONObject addDriverFile(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return driverLibraryService.addDriverFiles(data,currentUser);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:del")
    @RequestMapping("delete")
    public JSONObject delete(@RequestBody JSONObject data) {
        return driverLibraryService.delete(data);
    }

    @RequestMapping("adaptiveDriverLibrary")
    public JSONObject adaptiveDriverLibrary(@RequestBody JSONObject data) {
        return driverLibraryService.adaptiveDriverLibrary(data);
    }

}
